package com.yonyou.pmclouds.billview.util;

import com.yonyou.pmclouds.basecom.billstatus.BillStatusConst;
import com.yonyou.pmclouds.basecom.entity.SuperVO;
import com.yonyou.pmclouds.basecom.util.BeanHelper;
import com.yonyou.pmclouds.basecom.util.CommonFieldConst;
import org.apache.commons.lang3.ArrayUtils;

import java.text.SimpleDateFormat;

public class BillViewUtil {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 设置单据状态（适用于支持审批流的单据）
     * @param buziVOs
     */
    public static void setBillStatus(Object[] buziVOs){

        for (Object buziVO :
                buziVOs) {
            Byte billStatus = (byte) BeanHelper.getProperty(buziVO, CommonFieldConst.BILLSTATUS);
            String strBillStatus = "";
            switch (billStatus){
                case BillStatusConst.COMMON_APPROVING_STATUS :
                    strBillStatus = "审批中";
                    break;
                case BillStatusConst.COMMON_REJECT_STATUS :
                    strBillStatus = "已驳回";
                    break;
                case BillStatusConst.COMMON_APPROVED_STATUS :
                    strBillStatus = "审批通过";
                    break;
                case BillStatusConst.COMMON_COMMIT_STATUS :
                    strBillStatus = BillStatusConst.COMMON_COMMIT_STATUS_NAME;
                    break;
                case BillStatusConst.COMMON_FREE_STATUS :
                    strBillStatus = BillStatusConst.COMMON_FREE_STATUS_NAME;
                    break;

                default:strBillStatus="";
            }
            BeanHelper.setProperty(buziVO,"strBillstatus",strBillStatus);
        }

    }

    /**
     * 将日期字段转换为字符串设置到VO中
     * @param buziVOs
     * @param srcFields
     * @param destFields
     */
    public static void setFormatDate(Object[] buziVOs,String[] srcFields,String[] destFields){

        if(ArrayUtils.isEmpty(srcFields) || ArrayUtils.isEmpty(destFields) || ArrayUtils.isEmpty(buziVOs) || srcFields.length != destFields.length)
            return;

        for (Object buziVO : buziVOs) {
            for(int i = 0 ; i < srcFields.length ; i++){
                BeanHelper.setProperty(buziVO,destFields[i],sdf.format(BeanHelper.getProperty(buziVO,srcFields[i])));
            }
        }


    }

}
